package com.travel.find.findadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.travel.R;
import com.travel.find.findbean.HotBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import tools.MyGridView;

/**
 * Created by Administrator on 2016/10/20.
 */
public class BournRVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<HotBean>hotList;
    public BournRVAdapter(Context context, List<HotBean> hotList) {
        this.context = context;
        this.hotList=hotList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context)
                    .inflate(R.layout.rv_bourn_item, parent, false));
            return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            final MyViewHolder myViewHolder=(MyViewHolder)holder;
            final  int i = position;
            myViewHolder.tvBournTitle.setText(hotList.get(position).getTitle());
            if(hotList.get(position).getList().size()>6){
                final BournGVAdapter adapter=new BournGVAdapter(context,hotList.get(i).getList(),false);
                myViewHolder.gvBourn.setAdapter(adapter);
                myViewHolder.layoutBournMore.setVisibility(View.VISIBLE);
                myViewHolder.layoutBournMore.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        adapter.rush(true);
                        myViewHolder.layoutBournMore.setVisibility(View.GONE);
                    }
                });
            }else {
                BournGVAdapter adapter=new BournGVAdapter(context,hotList.get(position).getList(),false);
                myViewHolder.gvBourn.setAdapter(adapter);
                myViewHolder.layoutBournMore.setVisibility(View.GONE);
            }
    }

    @Override
    public int getItemCount() {
        return hotList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_bourn_title)
        TextView tvBournTitle;
        @Bind(R.id.gv_bourn)
        MyGridView gvBourn;
        @Bind(R.id.layout_bourn_more)
        RelativeLayout layoutBournMore;
        @Bind(R.id.tv_bourn_more2)
        TextView tv_bourn_more2;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
